package com.epic.adapter;

import java.util.ArrayList;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

import com.epic.item.MediaItem;
import com.epic.pager.ImagePager;

public class FragmentGalleryAdapter extends FragmentStatePagerAdapter {
	private ArrayList<MediaItem> mediaDatas;

	public FragmentGalleryAdapter(FragmentManager fm,
			ArrayList<MediaItem> mediaDatas) {
		super(fm);
		this.mediaDatas = mediaDatas;
	}

	@Override
	public Fragment getItem(int position) {
		ImagePager imagePager = new ImagePager();
		Bundle args = new Bundle();
		args.putSerializable("MEDIA ITEM", this.mediaDatas.get(position));
		imagePager.setArguments(args);
		return imagePager;
	}

	@Override
	public int getCount() {
		return mediaDatas.size();
	}

	public void addData(ArrayList<MediaItem> data) {
		mediaDatas.addAll(data);
		notifyDataSetChanged();
	}

	// public int getItemPosition(Object item) {
	// ImagePager fragment = (ImagePager) item;
	// MediaItem obj = fragment.getItem();
	// int position = mediaDatas.indexOf(obj);
	// if (position >= 0) {
	// return position;
	// } else {
	// return POSITION_NONE;
	// }
	// }

	public String getCaption(int position) {
		return mediaDatas.get(position).name;
	}

	public String getUrlMedia(int position) {
		return mediaDatas.get(position).img_url;
	}
}
